Detect wrong @doc annotations from unexpected packages#1291
Open
spkrka wants to merge 1 commit intospotify:mainfrom
Open
Detect wrong @doc annotations from unexpected packages#1291spkrka wants to merge 1 commit intospotify:mainfrom
spkrka wants to merge 1 commit intospotify:mainfrom
Conversation
When users accidentally use @doc from a different package (e.g., com.spotify.scio.avro.types.doc) instead of magnolify.shared.doc, the doc strings are silently ignored by Magnolify's type derivation. This change adds validation to detect this mistake and fail with a clear error message pointing users to the correct annotation. The validation: - Checks if any annotation has simpleName "doc" but isn't magnolify.shared.doc - Only fails if there's no correct @doc present - If both wrong and correct @doc exist, allows it (user knows what they're doing) Changes: - Add doc.extract() helper in shared module for centralized validation - Update AvroType, ParquetField, and ExampleType to use the helper - Add WrongDocAnnotationSuite with test cases Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
5c5cfbc to
82e3ebf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When users accidentally use
@docfrom a different package (e.g.,com.spotify.scio.avro.types.doc) instead ofmagnolify.shared.doc, the doc strings are silently ignored by Magnolify's type derivation. This leads to missing documentation in generated schemas with no warning.This change adds validation to detect this mistake and fail with a clear error message.
Changes
doc.extract()helper in shared module for centralized validationAvroType,ParquetField, andExampleTypeto use the helperWrongDocAnnotationSuitewith test casesHow it works
The validation:
getSimpleName == "doc"but isn'tmagnolify.shared.doc@docpresent@docexist, allows it (user knows what they're doing)Example error message
Test plan
WrongDocAnnotationSuitetests:@doconly → fails with clear error@doc→ succeeds (uses correct one)@doc→ succeeds🤖 Generated with Claude Code